Problem: Let $P$ be the plane passing through the origin with normal vector $\begin{pmatrix} 1 \\ -2 \\ 1 \end{pmatrix}.$  Find the matrix $\mathbf{P}$ such that for any vector $\mathbf{v},$ $\mathbf{P} \mathbf{v}$ is the projection of $\mathbf{v}$ onto plane $P.$
Explanation: Let $\mathbf{v} = \begin{pmatrix} x \\ y \\ z \end{pmatrix},$ and let $\mathbf{p}$ be the projection of $\mathbf{p}$ onto plane $P.$  Then $\mathbf{v} - \mathbf{p}$ is the projection of $\mathbf{v}$ onto the normal vector $\mathbf{n} = \begin{pmatrix} 1 \\ -2 \\ 1 \end{pmatrix}.$

[asy]
import three;

size(160);
currentprojection = perspective(6,3,2);

triple I = (1,0,0), J = (0,1,0), K = (0,0,1);
triple O = (0,-0.5,0), V = (0,1.5,1), P = (0,1.5,0);

draw(surface((2*I + 2*J)--(2*I - 2*J)--(-2*I - 2*J)--(-2*I + 2*J)--cycle),paleyellow,nolight);
draw((2*I + 2*J)--(2*I - 2*J)--(-2*I - 2*J)--(-2*I + 2*J)--cycle);
draw((P + 0.1*(O - P))--(P + 0.1*(O - P) + 0.2*(V - P))--(P + 0.2*(V - P)));
draw(O--P,green,Arrow3(6));
draw(O--V,red,Arrow3(6));
draw(P--V,blue,Arrow3(6));
draw((1,-0.8,0)--(1,-0.8,0.2)--(1,-1,0.2));
draw((1,-1,0)--(1,-1,2),magenta,Arrow3(6));

label("$\mathbf{v}$", V, N, fontsize(10));
label("$\mathbf{p}$", P, S, fontsize(10));
label("$\mathbf{n}$", (1,-1,1), dir(180), fontsize(10));
label("$\mathbf{v} - \mathbf{p}$", (V + P)/2, E, fontsize(10));
[/asy]

Thus,
\[\mathbf{v} - \mathbf{p} = \frac{\begin{pmatrix} x \\ y \\ z \end{pmatrix} \cdot \begin{pmatrix} 1 \\ -2 \\ 1 \end{pmatrix}}{\begin{pmatrix} 1 \\ -2 \\ 1 \end{pmatrix} \cdot \begin{pmatrix} 1 \\ -2 \\ 1 \end{pmatrix}} \begin{pmatrix} 1 \\ -2 \\ 1 \end{pmatrix} = \frac{x - 2y + z}{6} \begin{pmatrix} 1 \\ -2 \\ 1 \end{pmatrix} = \renewcommand{\arraystretch}{1.5} \begin{pmatrix} \frac{1}{6} x - \frac{1}{3} y + \frac{1}{6} z \\ -\frac{1}{3} x + \frac{2}{3} y - \frac{1}{3} z \\ \frac{1}{6} x - \frac{1}{3} y + \frac{1}{6} z \end{pmatrix} \renewcommand{\arraystretch}{1}.\]Then
\[\mathbf{p} = \begin{pmatrix} x \\ y \\ z \end{pmatrix} - \renewcommand{\arraystretch}{1.5} \begin{pmatrix} \frac{1}{6} x - \frac{1}{3} y + \frac{1}{6} z \\ -\frac{1}{3} x + \frac{2}{3} y - \frac{1}{3} z \\ \frac{1}{6} x - \frac{1}{3} y + \frac{1}{6} z \end{pmatrix} \renewcommand{\arraystretch}{1} = \renewcommand{\arraystretch}{1.5} \begin{pmatrix} \frac{5}{6} x + \frac{1}{3} y - \frac{1}{6} z \\ \frac{1}{3} x + \frac{1}{3} y + \frac{1}{3} z \\ -\frac{1}{6} x + \frac{1}{3} y + \frac{5}{6} z \end{pmatrix} \renewcommand{\arraystretch}{1} = \renewcommand{\arraystretch}{1.5} \begin{pmatrix} \frac{5}{6} & \frac{1}{3} & -\frac{1}{6} \\ \frac{1}{3} & \frac{1}{3} & \frac{1}{3} \\ -\frac{1}{6} & \frac{1}{3} & \frac{5}{6} \end{pmatrix} \renewcommand{\arraystretch}{1} \begin{pmatrix} x \\ y \\ z \end{pmatrix}.\]Hence,
\[\mathbf{P} = \boxed{\begin{pmatrix} \frac{5}{6} & \frac{1}{3} & -\frac{1}{6} \\ \frac{1}{3} & \frac{1}{3} & \frac{1}{3} \\ -\frac{1}{6} & \frac{1}{3} & \frac{5}{6} \end{pmatrix}}.\]